import { CodeListService } from '../app/codelist-service';
import { EntityBaseService, IContext, HttpResponse } from 'ibiz-core';
import { ISaleplatform, Saleplatform } from '../../entities';
import keys from '../../entities/saleplatform/saleplatform-keys';
import { SaleplatformDTOHelp } from '../../entities/saleplatform/saleplatform-dto-help';


/**
 * 销售平台服务对象基类
 *
 * @export
 * @class SaleplatformBaseService
 * @extends {EntityBaseService}
 */
export class SaleplatformBaseService extends EntityBaseService<ISaleplatform> {
    protected get keys(): string[] {
        return keys;
    }
    protected SYSTEMNAME = 'ActiveTYYW';
    protected APPNAME = 'App2';
    protected APPDENAME = 'Saleplatform';
    protected APPWFDENAME = 'SALEPLATFORM';
    protected APPDENAMEPLURAL = 'Saleplatforms';
    protected dynaModelFilePath:string = 'PSSYSAPPS/App2/PSAPPDATAENTITIES/Saleplatform.json';
    protected APPDEKEY = 'saleplatformid';
    protected APPDETEXT = 'saleplatformname';
    protected quickSearchFields = ['saleplatformname',];
    protected selectContextParam = {
    };

    constructor(opts?: any) {
        super(opts, 'Saleplatform');
    }

    newEntity(data: ISaleplatform): Saleplatform {
        return new Saleplatform(data);
    }

    /**
     * Create
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof SaleplatformService
     */
    async Create(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        _data = await this.beforeExecuteAction(_context,_data,'Create');
        if (!_data.srffrontuf || _data.srffrontuf != 1) {
            _data[this.APPDEKEY] = null;
        }
        if (_data.srffrontuf != null) {
            delete _data.srffrontuf;
        }
    _data = await SaleplatformDTOHelp.get(_context,_data);
        const res = await this.http.post(`/saleplatforms`, _data);
        res.data = await SaleplatformDTOHelp.set(_context,res.data);
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * Get
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof SaleplatformService
     */
    async Get(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        const res = await this.http.get(`/saleplatforms/${encodeURIComponent(_context.saleplatform)}`, _data);
        res.data = await SaleplatformDTOHelp.set(_context,res.data);
        res.data = await this.afterExecuteAction(_context,res?.data,'Get');
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * GetDraft
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof SaleplatformService
     */
    async GetDraft(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        _data[this.APPDENAME?.toLowerCase()] = undefined;
        _data[this.APPDEKEY] = undefined;
        const res = await this.http.get(`/saleplatforms/getdraft`, _data);
        res.data = await SaleplatformDTOHelp.set(_context,res.data);
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * Remove
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof SaleplatformService
     */
    async Remove(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        const res = await this.http.delete(`/saleplatforms/${encodeURIComponent(_context.saleplatform)}`);
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * Update
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof SaleplatformService
     */
    async Update(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        _data = await this.beforeExecuteAction(_context,_data,'Update');
    _data = await SaleplatformDTOHelp.get(_context,_data);
        const res = await this.http.put(`/saleplatforms/${encodeURIComponent(_context.saleplatform)}`, _data);
        res.data = await SaleplatformDTOHelp.set(_context,res.data);
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * FetchDefault
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof SaleplatformService
     */
    async FetchDefault(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        const res = await this.http.get(`/saleplatforms/fetchdefault`, _data);
        res.data = await SaleplatformDTOHelp.ToDataObjArray(_context,res.data);
        res.data = await this.afterExecuteActionBatch(_context,res?.data,'FetchDefault');
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * Select
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof SaleplatformService
     */
    async Select(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        const res = await this.http.get(`/saleplatforms/${encodeURIComponent(_context.saleplatform)}/select`);
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
}
